package com.yiyuan.app.config;

import com.wechat.pay.java.core.RSAAutoCertificateConfig;
import com.wechat.pay.java.service.payments.app.AppServiceExtension;
import com.wechat.pay.java.service.refund.RefundService;
import lombok.AllArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
@AllArgsConstructor
public class WxPayConfig {

    private final WxPayProperties properties;
    /**
     * 微信app支付
     */
    @Bean
    public RSAAutoCertificateConfig payConfig(){
        return new RSAAutoCertificateConfig.Builder()
                .merchantId(properties.getMerchantId())
                .privateKeyFromPath(properties.getPrivateKeyPath())
                .merchantSerialNumber(properties.getMerchantSerialNumber())
                .apiV3Key(properties.getApiV3key())
                .build();
    }
    /**
     * 微信app支付
     */
    @Bean
    public AppServiceExtension wxPayService(RSAAutoCertificateConfig wxPayConfig){
        return new AppServiceExtension.Builder().config(wxPayConfig).build();
    }

    /**
     * 微信app支付
     */
    @Bean
    public RefundService wxRefundService(RSAAutoCertificateConfig wxPayConfig){
        return new RefundService.Builder().config(wxPayConfig).build();
    }

}
